package com.itheima.dao;

import com.itheima.domain.Permission;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/*
* 资源权限
* */
public interface PermissionDao {

    //资源权限查询
    @Select("select * from permission")
    List<Permission> findAll() throws Exception;

    //根据角色id查询资源权限
    @Select("select * from permission where id in (select permissionId from role_permission where roleId = #{roleId})")
    List<Permission> findById(String roleId) throws Exception;

    //添加资源权限
    @Insert("insert into permission(permissionName,url) values(#{permissionName},#{url})")
    void save(Permission permission) throws Exception;

    //根据角色的id查询所有没有关联的资源权限
    @Select("select * from permission where id not in(select permissionId from role_permission where roleId = #{roleId})")
    List<Permission> findOtherPermission(String roleId) throws Exception;

    //根据id查询资源权限
    @Select("select * from permission where id = #{id}")
    Permission findByPermissionId(String id) throws Exception;

}
